package com.cartoon.dao.impl;

import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import com.cartoon.bean.Cartoon;
import com.cartoon.dao.CarDao;
import com.cartoon.util.DBUtil;

public class CarDaoImpl implements CarDao{
	JdbcTemplate jt = new JdbcTemplate(DBUtil.getDataSource());
	/**
	 *查询全部书籍
	 */
	@Override
	public List<Cartoon> selectAllCartoon() {
		String sql = "SELECT * FROM cart";
		return jt.query(sql, new BeanPropertyRowMapper<Cartoon>(Cartoon.class));
	}
	/**
	 *模糊查询书籍
	 */
	@Override
	public List<Cartoon> like(String carname) {
		String sql = "SELECT * FROM cart WHERE cart_name LIKE ? OR cart_release LIKE ? OR cart_release LIKE ? OR cart_type LIKE ?";
		return jt.query(sql, new BeanPropertyRowMapper<Cartoon>(Cartoon.class),'%'+carname+'%','%'+carname+'%','%'+carname+'%','%'+carname+'%');
	}
	/**
	 *添加漫画
	 */
	@Override
	public int addcart(String carName, String CarRelease, String carType, int carVisito, String carSummary,
			String carImg, int carLike, int carUpdate, int carFree, int carEnd, int carPiao, int carPublish,
			int carSigning, int carSelling) {
		String sql = "INSERT INTO cart VALUES(DEFAULT,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		return jt.update(sql,carName,CarRelease,carType,carVisito,carSummary,carImg,carLike,carUpdate,carFree,carEnd,carPiao,carPublish,carSigning,carSelling);
	}
	
	/**
	 *删除漫画
	 */
	@Override
	public int deletecart(String carName) {
		String sql = "DELETE FROM cart WHERE cart_name = ?";
		return jt.update(sql,carName);
	}
	/**
	 *修改书籍
	 */
	@Override
	public int updatecart(Cartoon Cartoon) {
		
		return 0;
	}
	/**
	 *通过是否签约查询漫画
	 */
	@Override
	public List<Cartoon> selectByqyue(int signing) {
		String sql = "SELECT * FROM cart WHERE cart_signing = ?";
		return jt.query(sql, new BeanPropertyRowMapper<Cartoon>(Cartoon.class),signing);
	}
	/**
	 *通过是否畅销查询图书
	 */
	@Override
	public List<Cartoon> selectByselling(int selling) {
		String sql = "SELECT * FROM cart WHERE cart_selling = ?";
		return jt.query(sql, new BeanPropertyRowMapper<Cartoon>(Cartoon.class),selling);
	}
	/**
	 *通过是否免费来查询漫画
	 */
	@Override
	public List<Cartoon> selectByfree(String free) {
		String sql = "SELECT * FROM cart WHERE cart_free = ?";
		return jt.query(sql, new BeanPropertyRowMapper<Cartoon>(Cartoon.class),free);
	}
	/**
	 *通过是否完结来查询漫画
	 */
	@Override
	public List<Cartoon> selectByend(String endof) {
		String sql = "SELECT * FROM cart WHERE cart_end = ?";
		return jt.query(sql, new BeanPropertyRowMapper<Cartoon>(Cartoon.class),endof);
	}
	@Override
	public List<Cartoon> selectBysex(String sex) {
		String sql = "SELECT * FROM cart WHERE cart_sex = ?";
		return jt.query(sql, new BeanPropertyRowMapper<Cartoon>(Cartoon.class),sex);
	}
	@Override
	public List<Cartoon> selectBycartPiao() {
		String sql = "SELECT * FROM cart";
		return jt.query(sql, new BeanPropertyRowMapper<Cartoon>(Cartoon.class));
	}

}
